package com.example.administrator.nl.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.administrator.nl.MainActivity;
import com.example.administrator.nl.R;
import com.example.administrator.nl.activity.register.RegisterTypeActivity;
import com.example.administrator.nl.base.BaseActivity;
import com.example.administrator.nl.util.ActivityManager;
import com.example.administrator.nl.util.DataUtil;
import com.example.administrator.nl.util.ToastUtil;
import com.leaf.library.StatusBarUtil;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 登录页面
 *
 * @author yuan
 */
public class LoginActivity extends BaseActivity {
    private int REQUEST = 0x00001;
    // 手机号输入框
    @BindView(R.id.et_login_login)
    EditText etLoginLogin;
    // 密码输入框
    @BindView(R.id.et_pass_login)
    EditText etPassLogin;
    // 注册用户
    @BindView(R.id.tv_register_login)
    TextView tvRegisterLogin;
    // 忘记密码
    @BindView(R.id.tv_forget_password_login)
    TextView tvForgetPasswordLogin;
    // 登录按钮
    @BindView(R.id.tv_login_login)
    TextView tvLoginLogin;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void init() {
        // 设置状态栏颜色
        StatusBarUtil.setColor(LoginActivity.this, getResources().getColor(R.color.color_white_ffffff));
        String phone = getIntent().getStringExtra("phone");
        if (null != phone) {
            // 关闭之前所有的Activity
            ActivityManager.getInstance().exit(this);
            etLoginLogin.setText(phone);
        }
    }

    @Override
    public int getContentView() {
        return R.layout.activity_login_actvity;
    }

    @OnClick({R.id.tv_register_login, R.id.tv_forget_password_login, R.id.tv_login_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_register_login:
                // 进入注册页面
                Intent intent = new Intent(LoginActivity.this, RegisterTypeActivity.class);
                startActivityForResult(intent, REQUEST);
                break;
            case R.id.tv_forget_password_login:
                break;
            case R.id.tv_login_login:
                // 进入主页面
                intent = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
//                login();
                break;


        }
    }

    /**
     * 进入主页面
     */
    private void login() {
        if (!TextUtils.isEmpty(etLoginLogin.getText())) {
            if (!TextUtils.isEmpty(etPassLogin.getText())) {
                Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                startActivity(intent);
            } else {
                ToastUtil.ToastLong("请输入密码");
            }

        } else {
            ToastUtil.ToastLong("请输入账号");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == REQUEST) {
            String phone = data.getStringExtra("phone");
            if (null != phone && !phone.equals("")) {
                etLoginLogin.setText(phone);
            }
        }
    }
}
